// pages/my-card/my-card.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hasCard: true, //是否有名片
    checkCard: true, //是否已认证名片
    navIdx: '',
    id: '',
    btmList: [
      { img1: '/img/card-logo1.png', img: '/img/card-logo.png', title: '名片' },
      { img1: '/img/card-home1.png', img: '/img/card-home.png', title: '官网' },
      // { img1: '/img/news-logo1.png', img: '/img/news-logo.png', title: '聊天' },
    ],
    productList:[
     
    ]
  },


  backTap: function () { //返回
    let pages = getCurrentPages();
    console.log(pages)
    if (pages.length == 1) {
      wx.switchTab({
        url: '/pages/index/index',
      })
    } else {
      wx.navigateBack({
        delta: 1,
      })
    }
  },

  goShareCardTap:function(){ //转发名片按钮
    wx.navigateTo({
      url: '/pages/share-card/share-card',
    })
  },

  selectedNavTap: function (e) { //底部跳转
    let that = this;
    let idx = e.currentTarget.dataset.idx;
    console.log(idx);
    if (idx==that.data.navIdx){
      return;
    }
    that.setData({
      navIdx: idx
    })
    if(idx==0){ //名片
      wx.redirectTo({
        url: '/pages/my-card/my-card',
      })
    }else if(idx==1){ //官网
      wx.redirectTo({
        url: '/pages/home/home',
      })
    }else{ //聊天
      wx.redirectTo({
        url: '',
      })
    }
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.showLoading({
      title: '加载中',
    })
    var that = this
    var user_id = wx.getStorageSync('userId')
    wx.request({
      url: app.globalData.host + 'member/getUserInfo',
      method: "GET",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        user_id: user_id
      },
      success: function (res) {
        console.log(res)
        console.log(res.data.data.user)
        that.setData({
          user: res.data.data.user,
          hasCard: res.data.data.user.is_card,
        })
        wx.setStorageSync('userInfo', res.data.data.user)
        var user = res.data.data.user;
        // if (user.is_card > 0 && user.enabled==0){
        //   that.setData({
        //     checkCard:false
        //   })
        // }
        wx.hideLoading();
      }
    })
  },


  createCardTap: function (e) { //创建名片
    app.confirmLogin(
      function () {
        wx.navigateTo({
          url: '/pages/card-msg-add/card-msg-add',
        })
      })
  },

  checkCardTap: function (e) {  //去认证名片
    app.confirmLogin(
      function () {
        wx.navigateTo({
          url: '/pages/card-check/card-check',
        })
      })
  },

  moadlCancel:function(){ //取消按钮
    wx.switchTab({
      url: '/pages/index/index',
    })
  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},
  
  /**
   * 防止蒙板触摸穿透
   */
  touchmoveTap(){}, 
  
})